﻿// ***********************************************************************
// Assembly         : GooglePredict
// Author           : aj
// Created          : 10-08-2010
//
// Last Modified By : aj
// Last Modified On : 10-08-2010
// Description      : 
//
//
// ***********************************************************************
namespace Google.API.Predict.Requests
{
    using Responses;
    using Newtonsoft.Json.Linq;
    using Core;
    using System.Linq;

    /// <summary>
    /// Metadata Request class based on "Check Training"
    /// Provides model information and training status
    /// http://code.google.com/apis/predict/docs/developer-guide.html#check-training
    /// </summary>
    public class MetadataRequest : GooglePredictionApiRequest<MetadataResponse>
    {
        /// <summary>
        /// Constant used to determine training status
        /// </summary>
        static readonly string[] Incomplete = {"Training hasn't completed.", "Training has not completed." };

        /// <summary>
        /// Creates a new Metadata Request (Check Training)
        /// </summary>
        public MetadataRequest()
        {
            RequestFormat = "{0}/{1}%2F{2}";
        }

        /// <summary>
        /// Executes the Check Training request
        /// Parses response and stores in "Response" field
        /// </summary>
        /// <returns>Parsed JSON response</returns>
        internal override JObject Execute()
        {
            var o = base.Execute();

            if (Response.Success)
            {
                Response.TrainingComplete = !Incomplete.Contains(Response.ModelInfo);
            }

            return o;
        }
    }
}
